import Vue from "vue";
import "normalize.css/normalize.css"; // a modern alternative to CSS resets

import Element from "element-ui";
import "./styles/element-variables.scss";
import 'element-ui/lib/theme-chalk/icon.css'

import "@/styles/index.scss"; // global css
import "@/styles/mixin.scss";

import VueCropper from 'vue-cropper'
Vue.use(VueCropper)

import App from "./App";
import store from "./store";
import router from "./router";

import WebIM from './utils/WebIM.js';//im

import Antd from 'ant-design-vue'
import 'ant-design-vue/dist/antd.css'
Vue.config.productionTip = false
Vue.use(Antd)


import VideoPlayer from 'vue-video-player'
require('video.js/dist/video-js.css')
require('vue-video-player/src/custom-theme.css')
import 'videojs-contrib-hls' //单是 RTMP 的话不需要第三方库，如果是 HLS 的话需要引入videojs-contrib-hls，看具体情况而定。
Vue.use(VideoPlayer);

import "./icons"; // icon
import "./permission"; // permission control
import "./utils/error-log"; // error log

import * as filters from "./filters"; // global filters

Vue.use(Element, {
  size: localStorage.getItem("size") || "medium" // set element-ui default size
});

//vue-carousel-3d 3D轮播插件
// import Vue from 'vue';
import Carousel3d from 'vue-carousel-3d';
Vue.use(Carousel3d);

import VuePhotoZoomPro from "vue-photo-zoom-pro";
Vue.use(VuePhotoZoomPro);
// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key]);
});

import Print from "@/utils/print2"; // 引入附件的js文件
Vue.use(Print); // 注册
Vue.prototype.returnValueToLable = function(
  value,
  dataList,
  propertyValue,
  propertyLabel
) {
  if (!dataList) {
    return "";
  }
  const dataPropertyValue = propertyValue || "value";
  const dataPropertyLabel = propertyLabel || "label";
  let valueLabel = "";
  if (typeof dataList === "object") {
    Object.keys(dataList).some(key => {
      if (dataList[key][dataPropertyValue].toString() === value.toString()) {
        valueLabel = dataList[key][dataPropertyLabel];
        return true;
      }
    });
  } else {
    dataList.some(item => {
      if (item[dataPropertyValue].toString() === value.toString()) {
        valueLabel = item[dataPropertyLabel];
        return true;
      }
    });
  }
  return valueLabel;
};
Vue.config.productionTip = false;

/**
 * checkButtonPermission
 * @param {'query','save','update','delete','confirm','cancel','pay'}
 */
Vue.prototype.checkButtonPermission = function(value) {

  if (value) {
    const myMenu = store.getters && store.getters.permission_myMenu;
    if (
      myMenu &&
      myMenu.length > 0 &&
      this.$route.meta &&
      this.$route.meta.code
    ) {
      let findValue = false;
      myMenu.some(item => {
        if (item.code === this.$route.meta.code) {
          if (item.children && item.children.length > 0) {
            item.children.some(children => {
              if (children.code.includes(value)) {
                findValue = true;
                return true;
              }
            });
          }
          return true;
        }
      });
      return findValue;
    } else {
      return true;
    }
  } else {
    return true;
  }
};
Vue.prototype.newCheckButtonPermission = function(value) {
  if (value) {
    const myMenu = store.getters && store.getters.btn_permission;
    if (myMenu && myMenu.length > 0) {
      return myMenu.some(item => item.code === value)
    } else {
      return true;
    }
  } else {
    return true;
  }
};
//手机号验证
Vue.prototype.$mobileValidator = function(rule, value, callback) {
  let myreg = /^[1][0-9]{10}$/;
  if (myreg.test(value)) {
    callback();
  } else {
    callback(new Error("请正确填写手机号"));
  }
};
//邮箱验证
Vue.prototype.$emailValidate = function(rule, value, callback) {
  const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  if (re.test(value)) {
    callback();
  } else {
    callback(new Error("请输入正确的邮箱"));
  }
};
/* 密码*/
Vue.prototype.$passwordValidator = function(rule, value, callback) {
  let myreg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,20}$/;
  if (myreg.test(value)) {
    callback();
  } else {
    callback(new Error("请输入8位以上字母和数字组合密码"));
  }
};

Vue.prototype.$getViewportSize = function() {
  return {
    width: window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width,
    height: window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height
  }
};

// 设置全局table列宽
Element.TableColumn.props.minWidth = {
  default: function() {
    return '210'
  }
}
Element.TableColumn.props.showOverflowTooltip ={type:Boolean, default: true}

new Vue({
  el: "#app",
  router,
  store,
  WebIM,
  render: h => h(App)
});
